#include <vector>
#include <cstdio>
#include <iostream>
#include <fstream>
#include <algorithm>


void solve(std::vector<std::vector<double> >& points, double val1, double val2)
{
    std::sort(points.begin(), points.end());
    std::vector<double> cur(points.size());
    for (size_t i = 0; i < points.size(); i++)
        cur[i] = points[i][0];
    
    int a = std::lower_bound(cur.begin(), cur.end(), val1) - cur.begin();
    int b = std::upper_bound(cur.begin(), cur.end(), val2) - cur.begin();
    
    for (size_t i = 0; i < points.size(); i++)
        std::rotate(points[i].begin(), points[i].begin() + 1, points[i].end());
   
    points.erase(points.begin() + b, points.end());
    points.erase(points.begin(), points.begin() + a);
}  

int main(){

    int d;
    std::cin >> d;

    std::vector<std::pair<double, double> > segment(d);
    for (int i = 0; i < d; i++)
        std::cin >> segment[i].first;

    for (int i = 0; i < d; i++)
    {
        double a;
        std::cin >> a;
        segment[i].second = segment[i].first + double(a);
    }


    int n;
    std::cin >> n;
    std::vector<std::vector<double> > points;
    for (int i = 0; i < n; i++)
	{
        std::vector<double> cur(d);
        for (int j = 0; j < d; j++)
            std::cin >> cur[j];
        points.push_back(cur);
    }
    
    std::vector<std::vector<double> > clone = points;
    
    int dim = d;
    int i = 0;
    while ((dim > 0) && points.size() != 0)
	{
        solve(points, segment[i].first, segment[i].second);
        i++;
        dim--;
    }

    
    std::vector<int> answer;
    if (points.size() == 0)
       answer.push_back(-1);
    else 
        for (size_t i = 0; i < points.size(); i++)
            for (size_t j = 0; j < clone.size(); j++)
                if (points[i] == clone[j])
                    answer.push_back(j + 1);
    std::sort(answer.begin(), answer.end());
    
    std::cout << answer.size() <<'\n';
    for (size_t i = 0; i < answer.size(); i++)
        std::cout << answer[i] << " ";
    return 0;
}